import { HashRouter, Routes, Route, Link, useRoutes } from "react-router-dom"
import { Provider } from "react-redux"
import store from "@/store/index.js"

import Permission from "./Permisson"


import Dashboard from "@/pages/dashboard/index.jsx"
import GoodList from "@/pages/good/goodList.jsx"
import GoodAdd from "@/pages/good/goodForm.jsx"
import User from "@/pages/user/index.jsx"

import { asyncRoutes } from "@/pages/index.jsx"

function createRoutes(asyncRoutes) {
    let result = [];  // []中包含了所有的路由规则
    asyncRoutes.forEach(route => {
        if (route.path && route.element) {
            result.push(
                <Route key={route.key} path={route.path} element={route.element}></Route>
            )
        }
        if (route.children) {
            route.children.forEach(route => {
                result.push(
                    <Route key={route.key} path={route.path} element={route.element}></Route>
                )
            })
        }
    })
    return result;
}

// console.log(createRoutes(asyncRoutes));


function App() {
    return (
        <HashRouter>
            <Provider store={store}>
                {/* <Routes> */}
                {/* <Route path="/" element={<Layout />}></Route> */}
                {/* /login不管你有没有权限，都是可以访问的 */}
                {/* <Route path="/login" element={<Login />}></Route> */}
                {/* </Routes> */}
                <Permission />
            </Provider>
        </HashRouter>
    );
}
export default App;
